1. Field of the Invention
The present invention relates in general to computer programs, and more particularly to translating an object oriented query into a relational query.
2. Description of the Related Art
Enterprise JavaBeans (EJB) is a specification of an architecture for developing and deploying component-based distributed applications. Distributed applications developed using the Enterprise JavaBeans architecture are scalable, transactional, and multi-user secure. Such a distributed application may be written once, and then deployed on various server platforms supporting the Enterprise JavaBeans specification. An EJB architecture comprises an EJB server, EJB containers that execute on the EJB server, and EJB's that execute in these EJB containers. EJB servers and EJB containers are developed and deployed by various middleware providers, and an application developer may use the EJB components to develop and deploy a component-based distributed application.
Enterprise Java Beans 2.0 (EJB 2.0) defines an EJB Query Language (EJBQL) which provides a solution for defining portable finder methods for container managed persistence (CMP) entity beans. Prior to EJB QL, the specification of CMP finder methods for a bean was vendor specific. If such a vendor specific bean is deployed into a different database having a different database schema mapping, then the vendor specific finder helper methods must be redefined. EJB Query Language makes the specification of finder methods easier and more portable.
The EJB Query Language provides a construct known as a path expression which specifies a navigation route from a previously referenced schema to a new schema. A path expression may appear in an EJB QL query in either a SELECT clause, a WHERE clause, or a FROM clause, and thus path expressions affect both the scope and the results of an EJB QL query). However, although an EJB QL query may be converted into a SQL query to execute against a database, the path expressions are extensions not found in SQL.
Path expressions may be translated to SQL joins operations when EJB's are mapped to relational tables. Path expressions in the SELECT clause are translated to a left outer join, path expressions in the FROM clause are translated to an inner join, and path expressions in the WHERE clause can be translated to either an inner join or an outer join depending on usage context. The translated SQL then consists a mixture of inner and left outer joins operations. Although a series of inner joins can appear in any order, the order of a mixture of inner joins and outer joins is critical for both the validity and performance of the query.
Several different techniques may be used to map EJB's to relational tables. In single-table inheritance, all of the attributes of all of the classes are stored in a single table. In multiple-table inheritance or distinct table inheritance, each entity bean is mapped to a separate table in which the table representing a class includes all of the attributes of the class, both those attributes defined by the class, and those attributes inherited by the class from its superclasses. Another mapping strategy is root-leaf inheritance in which each class in a hierarchy maps to a table that contains only those attributes actually defined in that class, plus the key columns shared by all members of the hierarchy.
Root leaf inheritance may present a particular problem as to the validity of a query generated by EJBQL. For example, root leaf inheritance maps each EJB to one or more tables. EJB Query Language allows a user to use a path expression to connect or relates a root leaf inheritance hierarchy or tree to another root leaf inheritance hierarchy. This mapping builds series of inner joins and outer joins between the root leaf inheritance hierarchies. If a source of a relationship starts from a top of one root leaf inheritance hierarchy and targets a bottom of another root leaf inheritance hierarchy, then the inheritance relationship requires a join from top to bottom of all of the related nodes (tables) of the first root leaf inheritance hierarchy to be joined with a join from top to bottom of all of the related nodes (tables) of the other root leaf inheritance hierarchy.
This series of joins results in an invalid query because, in this series, the bottom node of the first root leaf inheritance hierarchy is adjacent to the top node of the second root leaf inheritance hierarchy. As there is no relationship between the bottom node of the first root leaf inheritance hierarchy and the top node of the second root leaf inheritance hierarchy, the join between these two nodes cannot be performed because no join can be found. Therefore, the inability to perform the joins results in the invalid query.
Thus, there is a clearly felt need for an improved method, system, article of manufacture, and computer program product for translating from a query comprising root leaf inheritance to relational joins.